// JavaScript Document
$(document).ready(function(e) {
	$('div.tab-content').css('height',(screen.availHeight-275));
	$('#id_cabang').live('change',function(){ _show_data('');})
	$('#id_simpanan').live('change',function(){ _show_data('');})
	$('#c_bayare').live('change',function(){_show_data('1');})
	$('#c_cari').live('click',function(){ _show_data('1');})
	$('#d_Simpan').live('click',function(){ $('#myModal').modal('hide');});
	$('#b_Simpan').live('click',function(){ _set_simpanan();});
});

function _show_data(id)
{
	show_indicator('NewList',6);
	$.post('get_aktif_member',$('#frm5').serialize(),function(result){
		$('#NewList tbody').html(result);	
		(id=='')?
		fixHeader('NewList',230,400):'';
	})
}
function btn_click(id,aksi)
{
	switch(aksi)
	{
		case 'update':
		_get_detail_sp(id);
		$('#myModal').modal('show');
		break;
		case 'show_detaild':
		break;
		case 'deleted':
		break;	
	}
}
function _aksi(id,aksi)
{
	switch(aksi)
	{
		case 'add':
		jPrompt("Setup Simpanan","","Jumlah Simpanan",function(r)
		{ 
			if (r){_set_simpanan(id,r);}
		})
		break;
		case 'del':
		jConfirm('Yakin akan menghapus data ini','Ziebar Alert',function(r)
		{
			if(r)
			{
				$.post('delsetupsimpanan',{
					'id_member':id,
					'id_simpanan':$('#id_simpanan').val()},
				function(r){ _show_data('1');})
			}
		})
		break;
	}
	
}
function __set_simpanan(id,r)
{
	var cb=$('#s_'+id.replace('-','')).val();
	var al=$('#allm').is(':checked');
	$.post('setsetupsimpanan',{
		'id_simpanan':$('#id_simpanan').val(),
		'id_member'  :id,
		'val_simpanan':r,
		'c_bayar'	:cb,
		'allm'	   :al,
		'id_lokasi'  :$('#id_cabang').val()
		},function(result){ _show_data('1');})
}
function _get_detail_sp(id)
{
	$.post('getdetailsetupsimpanan',{'id_member':id,'id_simpanan':$('#id_simpanan').val()},
	function(result)
	{
		var r=$.parseJSON(result);
		$('#id_member').val(id).attr('readonly','readonly');
		$('#nm_member').val(r.nm_member).attr('readonly','readonly');
		$('#j_simpanan').val((r.id_simpanan)?r.id_simpanan:$('#id_simpanan').val()).select().attr('readonly','readonly');
		($('#id_simpanan').val() >3)?
		$('#jml_simpanan').val(r.val_simpanan).attr('readonly','readonly'):
		$('#jml_simpanan').val(r.val_simpanan).removeAttr('readonly');
		$('#jml_simpanan').priceFormat();
		formatAngka('jml_simpanan');
		$('#c_bayar').val(r.c_bayar).select();
		($('#id_simpanan').val() >3)?$('#allm').attr('disabled','disabled'):$('#allm').removeAttr('disabled');
		
	})
			
}
function _set_simpanan()
{
	show_indicator2('rst');
	$.post('setsetupsimpanan',$('#frm2').serialize()+'&'+$('#frm5').serialize(),function(result)
	{
		_show_data('1');
		$('#d_Simpan').click();
		$('#rst').html('');
	})
}